package db.tables;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import com.db.Table;
import db.beans.M_CSVImportTypeBean;

public class M_CSVImportTypeTable extends Table{

	public static final String TABLE_NAME = "M_CSV_IMPORT_TYPE";

	public static final String COL_IMPORT_TYPE_ID = "IMPORT_TYPE_ID";
	public static final String COL_IMPORT_TYPE_NAME = "IMPORT_TYPE_NAME";

	public static M_CSVImportTypeBean[] selectAll(Connection conn) throws SQLException{
		final String sql = "SELECT "
			+ COL_IMPORT_TYPE_ID + ","
			+ COL_IMPORT_TYPE_NAME
			+ " FROM " + TABLE_NAME
			;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		Vector<M_CSVImportTypeBean> v = new Vector<M_CSVImportTypeBean>();
        try{
    		stmt = conn.prepareStatement(sql);
    		rs = stmt.executeQuery();
    		int i = 0;
            while( rs.next() ) {
            	i = 0;
            	M_CSVImportTypeBean rec = new M_CSVImportTypeBean();
            	rec.setImportTypeId(rs.getInt(++i));
            	rec.setImportTypeName(rs.getString(++i));
            	rec.setDeleteFlag(rs.getInt(++i) == DELETE_FLAG);
            	v.add(rec);
            }

        } finally {
            if(rs != null){
                rs.close();
            }

            if (stmt != null){
            	stmt.close();
            }
        }
        return (M_CSVImportTypeBean[])v.toArray(new M_CSVImportTypeBean[v.size()]);
	}

	public static M_CSVImportTypeBean[] selectByImportTypeName(Connection conn, String importTypeName) throws SQLException{
		final String sql = "SELECT "
			+ COL_IMPORT_TYPE_ID + ","
			+ COL_IMPORT_TYPE_NAME
			+ " FROM " + TABLE_NAME
			+ " WHERE " + COL_IMPORT_TYPE_NAME + "=?"
			;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		Vector<M_CSVImportTypeBean> v = new Vector<M_CSVImportTypeBean>();
        try{
    		stmt = conn.prepareStatement(sql);
    		int i = 0;
    		stmt.setString(++i, importTypeName);
    		rs = stmt.executeQuery();
            while( rs.next() ) {
            	i = 0;
            	M_CSVImportTypeBean rec = new M_CSVImportTypeBean();
            	rec.setImportTypeId(rs.getInt(++i));
            	rec.setImportTypeName(rs.getString(++i));
            	rec.setDeleteFlag(rs.getInt(++i) == DELETE_FLAG);
            	v.add(rec);
            }

        } finally {
            if(rs != null){
                rs.close();
            }

            if (stmt != null){
            	stmt.close();
            }
        }
        return (M_CSVImportTypeBean[])v.toArray(new M_CSVImportTypeBean[v.size()]);
	}
}
